package cn.edu.scau.sec.rw.model.pro_manage.threadExe;

import cn.edu.scau.sec.rw.model.device_manage.Device.DeviceForProcess;
import cn.edu.scau.sec.rw.model.pro_manage.Process;
import cn.edu.scau.sec.rw.model.pro_manage.simulation.CPU;
import cn.edu.scau.sec.rw.model.pro_manage.simulation.Interrupt;

/**
 *
 */
public class DeviceThread extends Thread {
    /*private static DeviceForProcess dfp = new DeviceForProcess();

    public static DeviceForProcess getDfp() {
        return dfp;
    }*/

    @Override
    public void run() {
        while (true) {
            try {
                System.out.print("");
                if (Process.getReadyProcesses().size() > 0) {
                    CPU.getCpu().execute();
                }
                if (!Process.getIOFinishProcesses().isEmpty()) {
                    Interrupt.IOInterrupt(Process.getIOFinishProcesses().remove(0));
                    //Thread.sleep(1000 * 2);
                }

                if (!Process.getIOWaitProcesses().isEmpty()){
                    Interrupt.IOInterrupt(Process.getIOWaitProcesses().remove(0));
                   // Thread.sleep(1000 * 2);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    }
}
